import {
    GetAll,
    Get,
    Update,
    Delete,
    Create,
    ChangePassword,
    GetTreeList,
    GetAllPermissions,
    GetListByCustAsync,
    EnablePayChanelAsync,
    GetOptsAsync,
    GetAllByPart,
    GetList,
    GetEduConfig,
    Apprv,
    BatchAll,
    UpdatePassword,
    ActDeny,
    ActFrozen,
    CreateCourse,
    UpdateIsTop,
    GetById,
    SortNumMove,
    CreateExpand,
    CopyCourse,
    BatchShelf,
    GetRelation,
    DeleteRelation,
    UpdateCoupon,
    GetByCouponId,
    BatchCreate,
    BatchDelete,
    UpdateStatus,
    GetListNew,
    UpdateConfig,
    GetExchangeCodeList,
    GetBatchExchangeCode,
    ExportExcel,
}
    from '@/services/crud';
import { getCurrent } from '@/services/user';
import { Reducer, Effect } from 'umi';

export interface AbpModelType {
    namespace: string;
    state: any;
    effects: {
        get: Effect;
        getAll: Effect;
        update: Effect;
        create: Effect;
        delete: Effect;
        getList: Effect;
        changePassword: Effect;
        getTreeList: Effect;
        getAllPermissions: Effect;
        setCurrent: Effect;
        getCurrentUser: Effect;
        getListByCust: Effect;
        enablePayChanel: Effect;
        getOptsAsync: Effect;
        getAllByPart: Effect;
        getEduConfig: Effect;
        apprv: Effect;
        batchAll: Effect;
        updatePassword: Effect;
        actDeny: Effect;
        actFrozen: Effect;
        updateIsTop: Effect;
        createCourse: Effect;
        getById: Effect;
        sortNumMove: Effect;
        createExpand: Effect;
        copyCourse: Effect;
        batchShelf: Effect;
        getRelation: Effect;
        deleteRelation: Effect;
        updateCoupon: Effect;
        getByCouponId: Effect;
        batchCreate: Effect;
        batchDelete: Effect;
        updateStatus: Effect;
        getListNew: Effect;
        updateConfig: Effect;
        getExchangeCodeList: Effect;
        getBatchExchangeCode: Effect;
        exportExcel: Effect;
    };
    reducers: {
        deal: Reducer<any>;
        setCurrentUser: Reducer<any>;
    };
}

const AbpModel: AbpModelType = {
    namespace: 'Abp',
    state: {
        response: {},
        currentUser: {},
    },
    effects: {
        * get({ payload, control }, { call, put }) {
            const response = yield call(Get, payload, control);
            yield put({
                type: 'deal',
                payload: response,
            });
        },
        * getAll({ payload, control }, { call, put }) {
            const response = yield call(GetAll, payload, control);
            yield put({
                type: 'deal',
                payload: response,
            });
        },
        * getList({ payload, control }, { call, put }) {
            const response = yield call(GetList, payload, control);
            yield put({
                type: 'deal',
                payload: response,
            });
        },
        * update({ payload, control }, { call, put }) {
            const response = yield call(Update, payload, control);
            yield put({
                type: 'deal',
                payload: response,
            });
        },
        * create({ payload, control }, { call, put }) {
            const response = yield call(Create, payload, control);
            yield put({
                type: 'deal',
                payload: response,
            });
        },
        * delete({ payload, control }, { call, put }) {
            const response = yield call(Delete, payload, control);
            yield put({
                type: 'deal',
                payload: response,
            });
        },
        * apprv({ payload, control }, { call, put }) {
            const response = yield call(Apprv, payload, control);
            yield put({
                type: 'deal',
                payload: response,
            });
        },
        * changePassword({ payload, control }, { call, put }) {
            const response = yield call(ChangePassword, payload, control);
            yield put({
                type: 'deal',
                payload: response,
            });
        },
        * getTreeList({ payload, control }, { call, put }) {
            const response = yield call(GetTreeList, payload, control);
            yield put({
                type: 'deal',
                payload: response,
            });
        },
        * getAllPermissions({ }, { call, put }) {
            const response = yield call(GetAllPermissions);
            yield put({
                type: 'deal',
                payload: response,
            });
        },
        * getListByCust({ payload }, { call, put }) {
            const response = yield call(GetListByCustAsync, payload);
            yield put({
                type: 'deal',
                payload: response,
            });
        },
        * enablePayChanel({ payload }, { call, put }) {
            const response = yield call(EnablePayChanelAsync, payload);
            yield put({
                type: 'deal',
                payload: response,
            });
        },
        * getOptsAsync({ payload }, { call, put }) {
            const response = yield call(GetOptsAsync, payload);
            yield put({
                type: 'deal',
                payload: response,
            });
        },
        * getAllByPart({ payload, control }, { call, put }) {
            const response = yield call(GetAllByPart, payload, control);
            yield put({
                type: 'deal',
                payload: response,
            });
        },
        * getEduConfig({ payload }, { call, put }) {
            const response = yield call(GetEduConfig, payload);
            yield put({
                type: 'deal',
                payload: response,
            });
        },
        * getCurrentUser({ }, { call, put }) {
            const response = yield call(getCurrent);
            yield put({
                type: 'setCurrentUser',
                payload: response.result?.user,
            });
        },
        * setCurrent({ payload }, { call, put }) {
            yield put({
                type: 'setCurrentUser',
                payload,
            });
        },
        * batchAll({ payload, control }, { call, put }) {
            const response = yield call(BatchAll, payload, control);
            yield put({
                type: 'deal',
                payload: response,
            });
        },
        * updatePassword({ payload, control }, { call, put }) {
            const response = yield call(UpdatePassword, payload, control);
            yield put({
                type: 'deal',
                payload: response,
            });
        },
        * actDeny({ payload, control }, { call, put }) {
            const response = yield call(ActDeny, payload, control);
            yield put({
                type: 'deal',
                payload: response,
            });
        },
        * actFrozen({ payload, control }, { call, put }) {
            const response = yield call(ActFrozen, payload, control);
            yield put({
                type: 'deal',
                payload: response,
            });
        },
        * updateIsTop({ payload, control }, { call, put }) {
            const response = yield call(UpdateIsTop, payload, control);
            yield put({
                type: 'deal',
                payload: response,
            });
        },
        * createCourse({ payload, control }, { call, put }) {
            const response = yield call(CreateCourse, payload, control);
            yield put({
                type: 'deal',
                payload: response,
            });
        },
        * getById({ payload, control }, { call, put }) {
            const response = yield call(GetById, payload, control);
            yield put({
                type: 'deal',
                payload: response,
            });
        },
        * sortNumMove({ payload, control }, { call, put }) {
            const response = yield call(SortNumMove, payload, control);
            yield put({
                type: 'deal',
                payload: response,
            });
        },
        * createExpand({ payload, control }, { call, put }) {
            const response = yield call(CreateExpand, payload, control);
            yield put({
                type: 'deal',
                payload: response,
            });
        },
        * copyCourse({ payload, control }, { call, put }) {
            const response = yield call(CopyCourse, payload, control);
            yield put({
                type: 'deal',
                payload: response,
            });
        },
        * batchShelf({ payload, control }, { call, put }) {
            const response = yield call(BatchShelf, payload, control);
            yield put({
                type: 'deal',
                payload: response,
            });
        },
        * getRelation({ payload, control }, { call, put }) {
            const response = yield call(GetRelation, payload, control);
            yield put({
                type: 'deal',
                payload: response,
            });
        },
        * deleteRelation({ payload, control }, { call, put }) {
            const response = yield call(DeleteRelation, payload, control);
            yield put({
                type: 'deal',
                payload: response,
            });
        },
        * updateCoupon({ payload, control }, { call, put }) {
            const response = yield call(UpdateCoupon, payload, control);
            yield put({
                type: 'deal',
                payload: response,
            });
        },
        * getByCouponId({ payload, control }, { call, put }) {
            const response = yield call(GetByCouponId, payload, control);
            yield put({
                type: 'deal',
                payload: response,
            });
        },
        * batchCreate({ payload, control }, { call, put }) {
            const response = yield call(BatchCreate, payload, control);
            yield put({
                type: 'deal',
                payload: response,
            });
        },
        * batchDelete({ payload, control }, { call, put }) {
            const response = yield call(BatchDelete, payload, control);
            yield put({
                type: 'deal',
                payload: response,
            });
        },
        * updateStatus({ payload, control }, { call, put }) {
            const response = yield call(UpdateStatus, payload, control);
            yield put({
                type: 'deal',
                payload: response,
            });
        },
        * getListNew({ payload, control }, { call, put }) {
            const response = yield call(GetListNew, payload, control);
            yield put({
                type: 'deal',
                payload: response,
            });
        },
        * updateConfig({ payload, control }, { call, put }) {
            const response = yield call(UpdateConfig, payload, control);
            yield put({
                type: 'deal',
                payload: response,
            });
        },
        * getExchangeCodeList({ payload, control }, { call, put }) {
            const response = yield call(GetExchangeCodeList, payload, control);
            yield put({
                type: 'deal',
                payload: response,
            });
        },
        * getBatchExchangeCode({ payload, control }, { call, put }) {
            const response = yield call(GetBatchExchangeCode, payload, control);
            yield put({
                type: 'deal',
                payload: response,
            });
        },
        * exportExcel({ payload, control }, { call, put }) {
            const response = yield call(ExportExcel, payload, control);
            yield put({
                type: 'deal',
                payload: response,
            });
        },
    },
    reducers: {
        deal(state, action) {
            return { ...state, response: action.payload };
        },
        setCurrentUser(state, action) {
            return { ...state, currentUser: action.payload };
        },
    },
};
export default AbpModel;